package com.ruoyi.cms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.domain.CmsTemplet;
import com.ruoyi.cms.service.ICmsTempletService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 网站模板Controller
 * 
 * @author ruoyi
 * @date 2024-02-01
 */
@RestController
@RequestMapping("/cms/templet")
public class CmsTempletController extends BaseController
{
    @Autowired
    private ICmsTempletService cmsTempletService;

    /**
     * 查询网站模板列表
     */
    @PreAuthorize("@ss.hasPermi('cms:templet:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsTemplet cmsTemplet)
    {
        startPage();
        List<CmsTemplet> list = cmsTempletService.selectCmsTempletList(cmsTemplet);
        return getDataTable(list);
    }

    /**
     * 导出网站模板列表
     */
    @PreAuthorize("@ss.hasPermi('cms:templet:export')")
    @Log(title = "网站模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsTemplet cmsTemplet)
    {
        List<CmsTemplet> list = cmsTempletService.selectCmsTempletList(cmsTemplet);
        ExcelUtil<CmsTemplet> util = new ExcelUtil<CmsTemplet>(CmsTemplet.class);
        util.exportExcel(response, list, "网站模板数据");
    }

    /**
     * 获取网站模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:templet:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmsTempletService.selectCmsTempletById(id));
    }

    /**
     * 新增网站模板
     */
    @PreAuthorize("@ss.hasPermi('cms:templet:add')")
    @Log(title = "网站模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsTemplet cmsTemplet)
    {
        return toAjax(cmsTempletService.insertCmsTemplet(cmsTemplet));
    }

    /**
     * 修改网站模板
     */
    @PreAuthorize("@ss.hasPermi('cms:templet:edit')")
    @Log(title = "网站模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsTemplet cmsTemplet)
    {
        return toAjax(cmsTempletService.updateCmsTemplet(cmsTemplet));
    }

    /**
     * 删除网站模板
     */
    @PreAuthorize("@ss.hasPermi('cms:templet:remove')")
    @Log(title = "网站模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsTempletService.deleteCmsTempletByIds(ids));
    }
}
